<template>
    <div>
        <Form ref="formInline" :model="formInline"  inline>
            <FormItem prop="department_name">
                <Input type="text" v-model="formInline.department_name" placeholder="单位名称" clearable>
                </Input>
            </FormItem>
            <FormItem prop="monthly">
                <DatePicker v-model="formInline.monthly" type="month" :placeholder="yf" style="width: 200px"></DatePicker>
            </FormItem>
            <FormItem prop="company">
                <Select v-model="formInline.company" style="width: 200px" clearable placeholder="单位类型">
                    <Option value="机关">机关</Option>
                    <Option value="事业">事业</Option>
                    <Option value="企业">企业</Option>
                    <Option value="其他">其他</Option>
                </Select>
            </FormItem>
            <FormItem>
                <Button type="success" @click="search()">搜索</Button>
            </FormItem>
            <FormItem>
                <Button type="primary"  @click="exportData"><Icon type="ios-download-outline"></Icon>导出</Button>
            </FormItem>
        </Form>
        <Table :columns="columns11" :data="data10" border show-summary>
            <template slot-scope="{ row}" slot="file_text">
                <Icon type="md-download" size="24" @click="download(row)" v-if="row.file_text !=='暂无链接可下载'" />
            </template>
            <template slot-scope="{ row}" slot="action">
                <Button type="primary" size="small" style="margin-right: 5px" @click="show(row)">查看</Button>
            </template>
        </Table>
        <Page :total="params.totalRecord" show-sizer :page-size="params.pageSize" style="float: right;margin-top: 20px"
              show-total @on-change="pageAction" @on-page-size-change="pSizeChange"/>
    </div>
</template>

<script>
import { getZlDisciplineList } from '@/api/user'
export default {

  name: 'test',

  data () {
    return {
      yf: '',
      month: '',
      formInline: {
        department_name: '',
        monthly: '',
        company: ''
      },
      columns11: [
        {
          title: '序号列',
          key: 'index',
          type: 'index',
          width: '80',
          align: 'center'
        },
        {
          title: '单位',
          key: 'department_name',
          width: '200',
          align: 'center'
        },
        {
          title: '纪检组（单位纪委）组织会议推动体系建设次数',
          key: 'discipline_inspection_num',
          width: '200',
          align: 'center'
        },
        {
          title: '其中纪检组长（单位纪委书记）组织召开会议次数',
          key: 'discipline_inspection_meeting_num',
          width: '200',
          align: 'center'
        },
        {
          title: '专项监督数量（个）',
          key: 'special_num',
          width: '200',
          align: 'center'
        },
        {
          title: '专项监督涉及资金量（万元）',
          key: 'special_money',
          width: '200',
          align: 'center'
        },
        {
          title: '疑似问题数量（个）',
          key: 'suspected_problems_num',
          width: '200',
          align: 'center'
        },
        {
          title: '核实问题数量（个）',
          key: 'problem_num',
          width: '200',
          align: 'center'
        },
        {
          title: '问责处置人数',
          key: 'accountability_num',
          width: '200',
          align: 'center'
        },
        {
          title: '其中1：批评教育、诫勉谈话、组织调整人数',
          key: 'among_one',
          width: '200',
          align: 'center'
        },
        {
          title: '其中2：党纪政务处分人数',
          key: 'among_two',
          width: '200',
          align: 'center'
        },
        {
          title: '其中3：移送司法人数',
          key: 'among_three',
          width: '200',
          align: 'center'
        },
        {
          title: '每年可节约资金或避免经济损失（万元）',
          key: 'save_money',
          width: '200',
          align: 'center'
        },
        {
          title: '开展体系建设以来已挽回经济损失（万元）',
          key: 'salvation_money',
          width: '200',
          align: 'center'
        },
        {
          title: '节约、避免、挽回经济损失的文字说明材料附件上传',
          key: 'file_text',
          slot: 'file_text',
          width: '200',
          align: 'center'
        },
        {
          title: '备注',
          key: 'remarks',
          width: '100',
          align: 'center'
        },
        {
          title: '操作',
          slot: 'action',
          fixed: 'right',
          width: 150,
          align: 'center'
        }
      ],
      data10: [],
      params: { pageNo: 1, pageSize: 10, totalRecord: 0 },
      aId: ''
    }
  },

  props: {

  },

  components: {

  },

  computed: {

  },

  methods: {
    format (time, format) {
      var t = new Date(time)
      var tf = function (i) { return (i < 10 ? '0' : '') + i }
      return format.replace(/yyyy|MM/g, function (a) {
        switch (a) {
          case 'yyyy':
            return tf(t.getFullYear())
          case 'MM':
            return tf(t.getMonth() + 1)
        }
      })
    },
    async init () {
      this.aId = this.$store.state.user.severUserInfo.data.company_id
      var myDate = new Date()
      myDate.getFullYear() // 获取完整的年份(4位,1970-????)
      myDate.getMonth() // 获取当前月份(0-11,0代表1月)
      let y = myDate.getFullYear()
      let d = myDate.getMonth()
      if (d < 10) {
        d = '0' + d
      }
      let yd = y + '年' + d + '月'
      this.yf = yd
      this.month = y + '-' + d
      getZlDisciplineList().then(ret => {
        console.log(ret, 'ret@')
        this.data10 = ret.data.data.results
        this.data10.forEach(item => {
          if (item.file_text === '') {
            item.file_text = '暂无链接可下载'
          }
        })
        this.params.totalRecord = ret.data.data.totalRecord
      })
    },
    show (row) {
      console.log(row, 'row!!!!!')
      this.$router.push({
        name: 'disciplineInspectionf',
        query: {
          para: row
        }
      })
    },
    pageAction (current) {
      let data = {
        pageNo: current,
        department_name: this.formInline.department_name,
        monthly: this.format(this.formInline.monthly, 'yyyy-MM'),
        company: this.formInline.company
      }
      getZlDisciplineList(data).then(ret => {
        this.data10 = ret.data.data.results
        this.data10.forEach(item => {
          if (item.file_text === '') {
            item.file_text = '暂无链接可下载'
          }
        })
        this.params.totalRecord = ret.data.data.totalRecord
      })
    },
    pSizeChange (val) {
      getZlDisciplineList({ pageSize: val }).then(ret => {
        this.data10 = ret.data.data.results
        this.data10.forEach(item => {
          if (item.file_text === '') {
            item.file_text = '暂无链接可下载'
          }
        })
        this.params.totalRecord = ret.data.data.totalRecord
      })
    },
    search () {
      console.log(this.formInline.monthly, 'the')
      if (this.formInline.monthly !== '') {
        const data = {
          department_name: this.formInline.department_name,
          monthly: this.format(this.formInline.monthly, 'yyyy-MM'),
          company: this.formInline.company
        }
        getZlDisciplineList(data).then(ret => {
          this.data10 = ret.data.data.results
          this.data10.forEach(item => {
            if (item.file_text === '') {
              item.file_text = '暂无链接可下载'
            }
          })
          this.params.totalRecord = ret.data.data.totalRecord
        })
      } else {
        const data = {
          department_name: this.formInline.department_name,
          monthly: this.month,
          company: this.formInline.company
        }
        getZlDisciplineList(data).then(ret => {
          this.data10 = ret.data.data.results
          this.data10.forEach(item => {
            if (item.file_text === '') {
              item.file_text = '暂无链接可下载'
            }
          })
          this.params.totalRecord = ret.data.data.totalRecord
        })
      }
    },
    download (row) {
      // console.log(row)
      window.location.href = row.file_text
    },
    exportData () {
      let url = 'http://sstpw.tripln.top/wl/demo/commonExcelExport?id=36&companyId=' + this.aId
      window.location.href = url
    }
  },

  watch: {

  },

  mounted () {
    this.init()
  }

}
</script>

<style scoped>

</style>
